
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Marwen
 */
public class ListeClientTrader extends javax.swing.JFrame {

    private Object[][] data;
    AcceuilTrader acceuil;
    public ListeClientTrader(AcceuilTrader ac) {
        initComponents();
        acceuil=ac;
        this.setTitle("Lise des clients ");
                tableClient.setEnabled(false);
                remplirliste();
    }
    public void remplirliste(){
        try {
            DbManip.viderListe(tableClient);
            DefaultTableModel model = (DefaultTableModel) tableClient.getModel();
           // this.setContentPane(jScrollPane1);
            this.tableClient.setRowHeight(35);
            DbManip.requete = "SELECT ID_CLIENT, ID_ENTREPRISE,nom_client,prenom_client,adresse_client,tel_client,email_client,profession_client"
            + " from client where matricule='"+DbManip.traderId+"'";
            DbManip.executer(DbManip.requete);
            int m = DbManip.rsmd.getColumnCount();
            DbManip.rs.last();
            int n = DbManip.rs.getRow();
            int i = 0;
            DbManip.rs.beforeFirst();
            data = new Object[n][m];
            while (DbManip.rs.next()) {
                int id_client = DbManip.rs.getInt("id_client");
                int ID_ENTREPRISE = DbManip.rs.getInt("ID_ENTREPRISE");
                String NOM_CLIENT = DbManip.rs.getString("NOM_CLIENT").substring(0,DbManip.rs.getString("NOM_CLIENT").indexOf("  "));
                String PRENOM_CLIENT = DbManip.rs.getString("PRENOM_CLIENT").substring(0,DbManip.rs.getString("PRENOM_CLIENT").indexOf("  "));
                String ADRESSE_CLIENT = DbManip.rs.getString("ADRESSE_CLIENT").substring(0,DbManip.rs.getString("ADRESSE_CLIENT").indexOf("  "));
                String TEL_CLIENT = DbManip.rs.getString("TEL_CLIENT").substring(0,DbManip.rs.getString("TEL_CLIENT").indexOf("  "));
                String EMAIL_CLIENT = DbManip.rs.getString("EMAIL_CLIENT").substring(0,DbManip.rs.getString("EMAIL_CLIENT").indexOf("  "));
                String PROFESSION_CLIENT = DbManip.rs.getString("PROFESSION_CLIENT").substring(0,DbManip.rs.getString("PROFESSION_CLIENT").indexOf("  "));             
               // String type = DbManip.rs.getString("type").substring(0,DbManip.rs.getString("type").indexOf("  "));
               // int quantite = DbManip.rs.getInt("quantite");
                data[i][0] = id_client;
                data[i][1] = ID_ENTREPRISE;
                data[i][2] = NOM_CLIENT;
                data[i][3] = PRENOM_CLIENT;
                data[i][4] = ADRESSE_CLIENT;
               
                data[i][5] = TEL_CLIENT;
                data[i][6] = EMAIL_CLIENT;
                data[i][7] =PROFESSION_CLIENT;
                model.addRow(new Object[]{id_client, ID_ENTREPRISE, NOM_CLIENT, PRENOM_CLIENT, ADRESSE_CLIENT, TEL_CLIENT,EMAIL_CLIENT,PROFESSION_CLIENT});

                i++;
            
}       }
        catch (SQLException ex) {
            Logger.getLogger(ListeClientTrader.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tableClient = new javax.swing.JTable();
        panheader = new javax.swing.JPanel();
        home = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tableClient.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID_CLIENT", "ID_Entreprise", "Nom client", "PRENOM CLIENT", "Adresse CLIENT", "Telephone Client", "Email Client", "Profession Client"
            }
        ));
        jScrollPane1.setViewportView(tableClient);

        panheader.setBackground(new java.awt.Color(0, 153, 153));

        home.setBackground(new java.awt.Color(0, 153, 153));
        home.setFont(new java.awt.Font("Vani", 1, 12)); // NOI18N
        home.setForeground(new java.awt.Color(255, 255, 255));
        home.setText("Acceuil");
        home.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                homeActionPerformed(evt);
            }
        });

        jLabel1.setBackground(new java.awt.Color(0, 0, 0));
        jLabel1.setFont(new java.awt.Font("Vani", 0, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("   Trader:  ");

        jLabel2.setFont(new java.awt.Font("Vani", 1, 14)); // NOI18N
        jLabel2.setText("NET TRADING");

        javax.swing.GroupLayout panheaderLayout = new javax.swing.GroupLayout(panheader);
        panheader.setLayout(panheaderLayout);
        panheaderLayout.setHorizontalGroup(
            panheaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panheaderLayout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 145, Short.MAX_VALUE)
                .addComponent(home, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        panheaderLayout.setVerticalGroup(
            panheaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(home, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panheader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(panheader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void homeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homeActionPerformed

        acceuil.setLocation(this.getLocation());
        acceuil.setVisible(true);
        this.setVisible(false);
        

        // TODO add your handling code here:
    }//GEN-LAST:event_homeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton home;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel panheader;
    private javax.swing.JTable tableClient;
    // End of variables declaration//GEN-END:variables
}
